// var srcMenuId;

/**
 * 移动菜单
 * 
 * @param {}
 *            id
 */
function moveMenu(id, name, type) {
	// srcMenuId = id;
	var targetId;
	var targetType;

	var root = new Ext.tree.AsyncTreeNode({
				text : '根节点',
				draggable : false,
				id : '0'
			});

	var moduleTree = new Ext.tree.TreePanel({
				layout : 'fit',
				useArrows : false,
				autoScroll : false,
				animate : false,
				enableDD : false,
				containerScroll : true,
				expandable : true,
				rootVisible : false,
				singleExpand : false,
				animate : true,
				border : false,
				frame : false,
				root : {
					nodeType : 'async'
				},
				// auto create TreeLoader
				dataUrl : context + '/system/module.do?method=allmoduletree'

			});

	moduleTree.on("click", function(node, event) {
				if (id == node.attributes.realid
						&& type == node.attributes.type) {
					Ext.getCmp('menuMoveButton').disable();
					Ext.Msg.alert('提示', '菜单不能移至此节点下！');
				} else {
					var srcNode = moduleTree.getNodeById('menu_' + id);

					if (srcNode.parentNode.id == node.id) {
						Ext.getCmp('menuMoveButton').disable();
						Ext.Msg.alert('提示', '菜单已经在此节点下！');
					} else {
						targetId = node.attributes.realid;
						targetType = node.attributes.type;
						Ext.getCmp('menuMoveButton').enable();
					}
				}
			});

	moduleTree.expandAll();

	var win = new Ext.Window({
				title : '将菜单 \'' + name + '\' 移动至...',
				renderTo : Ext.getBody(),
				closable : true,
				resizable : false,
				// maximizable : true,
				width : 350,
				height : 400,
				border : false,
				plain : true,
				layout : 'fit',
				modal : true,
				items : [moduleTree],
				buttons : [{
					id : 'menuMoveButton',
					disabled : true,
					text : '确 定',
					handler : function() {
						Ext.Ajax.request({
									url : context
											+ "/system/module.do?method=move",
									method : 'POST',
									async : false,
									params : {
										id : id,
										targetId : targetId,
										targetType : targetType
									},
									success : function(response, options) {
										var o = Ext.util.JSON
												.decode(response.responseText);
										if (!o.success) {
											Ext.Msg.alert('提示', '移动菜单发送错误！');
										} else {
											Ext.Msg.alert('提示', '已成功移动菜单！');
											moduleTreeReload();
											if (Ext.get("tab_menuedit")) {
												moduleTreeTabs.remove(0);
											}
											win.close();
											win = null;
										}
									}
								});
					}
				}, {
					text : '关 闭',
					handler : function() {
						win.close();
						win = null;
					}
				}]
			});

	win.show(this);
}